#include "fault.hpp"
#include "commtick.hpp"

using namespace motion;
using namespace device;

fault* fault::mRegisterQueue[FAULT_MAX_SURPPORT] = {0};
bool fault::mFaultTickEnable = false;

bool fault::CompareValue(bool isResume) ///>数据对比处理父类创建
{
	return(false);
}

bool fault::FaultTimerTick(void)
{
	uint8_t i;
	
	for(i = 0; i < FAULT_MAX_SURPPORT; i++)
	{
		if(mRegisterQueue[i] != 0)
		{
			mRegisterQueue[i]->mTicked();
		}
	}
	return(true);
}

void fault::mTicked(void){ }///> 故障回调函数，父类创建

fault::fault(void)
{
	uint8_t i;
	mRegisterQueueIndex = -1;
	FaultEnable = false;
	LimitEnable = false;
	WarningEnable = false;
	mWarningCount = 0;
	WarningStatus = false;
	WarningTrigTime = 0;
	LimitValue = 0;
	FaultStatus = FAULT_STATUS_NONE;
	
	for(i = 0; i < FAULT_MAX_ITEMSURPPORT; i++)
	{
		ResourceValue[i] = 0;
	}
	for(i = 0; i < FAULT_MAX_SURPPORT; i++)
	{
		if(mRegisterQueue[i] == 0)
		{
			mRegisterQueueIndex = i;
			mRegisterQueue[i] = this;
			break;
		}
	}
	if(i >= FAULT_MAX_SURPPORT)
	{
		return;
	}
	if(!mFaultTickEnable)
	{
		commtick::RegisteTick(FaultTimerTick,1);  ///> 注册滴答函数
		mFaultTickEnable = true;
	}
}

void fault::Unregister(void)
{
	if(mRegisterQueueIndex != -1)
	{
		mRegisterQueue[mRegisterQueueIndex] = 0;
	}
}

fault::~fault()
{
	Unregister();
}

void fault::Reset()
{
	FaultStatus = FAULT_STATUS_NONE;
}
